﻿
//pre loads the 3 images for the profile so that the
//mouseover event should be as smooth as possible
//using preload jQuery plugin 
function preLoadImgs() {


    $.preload(  '../images/myprofilepic.jpg',
                '../images/famImg.jpg',
                '../images/signImg.jpg',
                '../images/programmer_cartoon.jpg',
                '../images/info.png',
                '../images/error.png',
                '../images/fancybox_sprite.png');
     
       
   
}












$(document).ready(function () {

    preLoadImgs();

    //showLoggedOutContent();



    $("#registerBtn").click(function () {

        window.location.replace("/register");


    });

    $("#aboutBtn").click(function () {

        var msg = "";
        msg += '<div id="aboutUsTitle">';

       
        msg += 'The Developers:';

       
        
        msg += '</div>';
        msg += "<div id='aboutUsDiv' >";
		msg += '<div class="developerText">';
		msg += '<img id="profileImg0" class="profileImg " src="../images/myprofilepic.jpg" alt="Profile Picture" />';
		msg += 'Name: Baruch Lerner </br> Title: CEO of Ex5';
        msg += '</div>';
		msg += '<div class="developerText">';
		msg += '<img id="profileImg1" class="profileImg  " src="../images/famImg.jpg" alt="Profile Picture" />';
		msg += 'Name: Shimi Bernholtz </br> Title: Head of R&D';
		msg += '</div>';

        msg += '</div>';

        

        $.fancybox(
	                	 msg
                         ,
                         {
                             'autoDimensions': true,
                             'autoScale': true,
                             'scrolling':'no',   
                             'transitionIn': 'none',
                             'transitionOut': 'none'
                         }
	                );

    });

    $("#submitBtn").click(function () {




        var userName = $("#username").val();
        var passWord = $("#password").val();


        var request = $.ajax({
            type: 'POST',
            url: "/login",
            dataType: "json",
            data: { username: userName, password: passWord }


        });
        request.done(function (data) {

            if (data.redirect) {
                // data.redirect contains the string URL to redirect to
                window.location.replace(data.redirect);
            }
            else {

                var msg = "";

                msg += "<div id='fancyMsg' class='msg'>Please try to login again!!";
                msg += "</br>" + data.msg + "</div>";


                $.fancybox(
	                	 msg
                         ,
                         {
                             'autoDimensions': false,
                             'width': 350,
                             'height': 'auto',
                             'transitionIn': 'none',
                             'transitionOut': 'none'
                         }
	                );
            }

        });







    });




});
